package com.frogs.ucenter.v1.request;

import javax.servlet.http.HttpServletRequest;

import com.frogs.framework.util.StringUtil;
import com.frogs.framework.web.HttpRequestInfo;
import com.frogs.system.util.ApiUrlParamEnum;
import com.frogs.system.web.api.request.Request;
import com.frogs.system.web.exception.RequestIllegalException;

/**
 * 发送邮件
 * @author hongyuhao
 *
 */
public class MailingSendRequest extends Request {
	
	private static final long serialVersionUID = 6485274445050462554L;

	//用户邮箱地址
	private String email;
	
	//用户从属的活动ID（需在邮件系统获得）
	private int compId;
	
	//邮件ID
	private int mailId;
	
	@Override
	public void parse(HttpServletRequest request) {
		
		HttpRequestInfo requestInfo = new HttpRequestInfo(request);
		
		
		email = request.getParameter(ApiUrlParamEnum.email.getParamName());
		if(StringUtil.isEmpty(email)) {
			throw new RequestIllegalException("缺少邮箱地址参数！");
		} else if(!StringUtil.isEmail(email)) {
			throw new RequestIllegalException("邮箱地址格式错误！");
		}
		
		mailId = requestInfo.getIntParameter(ApiUrlParamEnum.mailId.getParamName(), -1);
		if(mailId < 0) {
			throw new RequestIllegalException("缺少邮件ID！");
		}
		compId = requestInfo.getIntParameter(ApiUrlParamEnum.campaignId.getParamName(), -1);
		if(compId < 0) {
			throw new RequestIllegalException("缺少活动ID！");
		}
		
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public int getCompId() {
		return compId;
	}

	public void setCompId(int compId) {
		this.compId = compId;
	}

	public int getMailId() {
		return mailId;
	}

	public void setMailId(int mailId) {
		this.mailId = mailId;
	}
	
}
